package leetcode.easy;

import leetcode.base.ListNode;

/**
 * ClassName: $141_HasCycle
 * Description:
 * date: 2021-12-13 19:17
 *
 * @author liyifan
 */
public class $141_HasCycle {
    public boolean hasCycle(ListNode head) {
        if (head == null)
            return false;
        ListNode slow = head;
        ListNode fast = head;
        while (fast != null && fast.next != null) {
            fast = fast.next.next;
            slow = slow.next;

            if (fast == slow) {
                return true;
            }
        }
        return false;
    }
}
